<?php

namespace app\index\controller;

use app\index\controller\Base;
use think\db\Query;


class Index extends Base
{

     public function _initialize()
    {
        $this->init();
    }

    // 显示前台首页
     public function index()
    {
        // 调用model查询频道,分类标签,推荐文章
        $M = model('index');
        $this->assign('title','主页');
        $this->assign('channel',$M->getchannels());
        $this->assign('posts',$M->getposts());
        $this->assign('label',$M->getlabel());
        return $this->fetch();
    }


    public function list($id)
    {   
        // 加载列表页
        $M = model('index');
        $this->assign('title','主页');
        $this->assign('channel',$M->getchannels());
        $this->assign('list',$M->getchannel($id));
        return $this->fetch();
    }

    // 根据 id 显示帖子详情
     public function postinfo($id)
    {
        $M = model('Post');
        $post = $M->getpost($id);
        $this->assign('channel',$M->getchannels());
        $this->assign('title',$post['title']);
        $this->assign('post',$post);
        $this->assign('user',$M->getuser($post['uid']));
        return $this->fetch();
    }

}
